﻿using System;
using System.Text;
using RabbitMQ;
using RabbitMQ.Client;
using BrukeFramework;

namespace RabbitMQSendConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory();
            factory.HostName = "47.112.201.220";//85-->5672
            factory.UserName = "bruke";
            factory.Password = "123456";
            factory.VirtualHost = "my_vhost";
            factory.Endpoint = new AmqpTcpEndpoint("47.112.201.220", 85);//因为远程的服务器端口是85，不是默认5672

            var channelQueueName = "BrukeQueue";
            while (true)
            {
                Console.WriteLine("请输入要发送的消息", ConsoleColor.Red);
                var input = Console.ReadLine();
                using (var connection=factory.CreateConnection())
                {
                    using (var channel=connection.CreateModel())
                    {
                        channel.QueueDeclare(channelQueueName, false,false,false,null);//定义队列
                        var properties = channel.CreateBasicProperties();//属性
                        properties.DeliveryMode = 1;//非持久性
                        channel.BasicPublish("", channelQueueName, properties, Encoding.UTF8.GetBytes(input));//发送消息
                    }
                }
            }

        }
    }
}
